<template>
  <div class="register">
    <!-- 2.绑定数据 -->
    <div>
      <img src="../../assets/img/orange.png" alt="">
    </div>
    <van-cell-group>
      <van-field v-model="user.phone" placeholder="请输入手机号" />
    </van-cell-group>
    <van-cell-group>
      <van-field v-model="user.nickname" placeholder="请输入昵称" />
    </van-cell-group>
    <van-cell-group>
      <van-field v-model="user.password" placeholder="请输入密码" />
    </van-cell-group>
    <div class="text-center" style="margin: 16px;">
      <van-button block round type="info" @click="register">注册</van-button>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant"
import {reqRegister} from "../../http/api"
export default {
  // 1.初始化表单数据
  data() {
    return {
      user: {
        phone: "",
        nickname: "",
        password: "",
      },
    };
  },
  methods: {
    //3.点了注册按钮
    register() {
      //发送请求
      reqRegister(this.user).then((res) => {
        // console.log(res);
        if (res.data.code == 200) {
          Toast(res.data.msg);
          //跳转登陆
          this.$router.push("/login")
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
@import url("../../less/index.less");
.register {
  display: flex;
  flex-direction: column;
  height: 100vh;
  justify-content: center;
  align-content: center;
}
.register img{
  display: block;
  margin: auto;
  margin-bottom: 0.5rem;
}
</style>